package com.attack.api.utils;

import java.util.UUID;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
//如何生成token
@Component
public class TokenUtils {
	@Autowired
	private BaseRedisService baseRedisService;
	private long timeOut=60*60*2l;
	/**
	 * 生成令牌
	 * @return
	 */
	public String getToken(){
		String token="token_" +UUID.randomUUID();
		baseRedisService.setString(token, token, timeOut);
		return token;
	}
	/**
	 * redis查询redis是否还存在
	 * @param token
	 * @return
	 */
	public  boolean findToken(String token){
		String result=(String) baseRedisService.getString(token);
		if(StringUtils.isEmpty(result)){
			return false;
		}
		baseRedisService.delKey(token);
		return true;
	}

}
